home *** CD-ROM | disk | FTP | other *** search
GW-BASIC | 1985-11-17 | 18.0 KB | 587 lines |
- 100 CLS
- 110 A$=STRING$(80,205)
- 120 PRINT A$
- 130 PRINT TAB(29)"TIC TAC TOE 2010-A.BAS "
- 140 COLOR 23,0,0
- 150 PRINT :PRINT :PRINT TAB(38)"IPCO"
- 160 COLOR 7,0,0
- 170 PRINT :PRINT :PRINT TAB(29)"INTERNATIONAL PC OWNERS"
- 180 PRINT :PRINT :PRINT TAB(17)"p.o. box 10426, pittsburgh, pennsylvania 15234"
- 190 PRINT A$
- 200 PRINT :PRINT :PRINT :PRINT :PRINT
- 210 PRINT TAB(28)"PRESS ANY KEY TO CONTINUE"
- 220 A$=INKEY$:IF A$="" THEN 220
- 230 CLS
- 240 REM **************************************************
- 250 REM * Name - Tic Tac Toe *
- 260 REM * Author - David R Quiggin *
- 270 REM * Remarks - If you like this game, I am selling *
- 280 REM * a package of 10 games and programs on disk *
- 290 REM * for $19.95 plus 2.00 shipping and handling. *
- 300 REM * To order or request more information send to: *
- 310 REM * Pittsburgh Computer Exchange *
- 320 REM * 112 Marble Drive *
- 330 REM * Bridgeville, Pa, 15017 *
- 340 REM **************************************************
- 350 SCREEN 0,0,0:KEY OFF: CLS: WIDTH 80
- 360 DIM SQ(9) 'store whether positon used
- 370 GOSUB 5950 'seed random nbr
- 380 CLS
- 390 GOSUB 3670 'initialize
- 400 LOCATE 5,47,0:PRINT "Choose which game you want"
- 410 LOCATE 7,47,0:PRINT " 1 - 2 persons play"
- 420 LOCATE 9,47,0:PRINT " 2 - Basic game against the"
- 430 LOCATE 10,47,0:PRINT " computer"
- 440 LOCATE 12,47,0:PRINT " 3 - More difficult game"
- 450 LOCATE 13,47,0:PRINT " against the computer"
- 460 LOCATE 15,47,0:PRINT " 4 - Most difficult game"
- 470 LOCATE 16,47,0:PRINT " against the computer"
- 480 LOCATE 18,47,0:PRINT " 5 - Instructions"
- 490 LOCATE 20,50,0:PRINT "Which do you want?"
- 500 LOCATE 21,50,0:PRINT " Enter the number __"
- 510 CH$=INKEY$:IF CH$="" THEN GOTO 510 'loop to sense input
- 520 IF CH$=CHR$(27) THEN GOTO 710 'ESC to end
- 530 IF CH$="1" OR CH$="2" OR CH$="3" OR CH$="4" OR CH$="5" THEN GOTO 560
- 540 LOCATE 22,50,0:PRINT "Error, please reenter"
- 550 GOTO 490
- 560 IF CH$="1" THEN GOSUB 1390 ' 2 player game
- 570 IF CH$="2" THEN GOSUB 710 ' Basic game against computer
- 580 IF CH$="3" THEN GOSUB 710 ' more difficult game against computer
- 590 IF CH$="4" THEN GOSUB 5110 ' Most difficult game against computer
- 600 IF CH$="5" THEN GOSUB 4070:GOTO 400 ' give instructions
- 610 LOCATE 20,47,0:PRINT " Play again (Y or N)"
- 620 YN$=INKEY$
- 630 IF YN$="" THEN GOTO 620
- 640 IF YN$="Y" OR YN$="y" THEN GOTO 380
- 650 IF YN$="1" OR YN$="2" OR YN$="3" OR YN$="4" THEN GOTO 660 ELSE GOTO 690
- 660 CH$=YN$
- 670 CLS:GOSUB 3670 'initialize
- 680 GOTO 560 'start the appropriate game (without having to go thru menu)
- 690 SYSTEM
- 700 END '******
- 710 REM -- Games 2 and 3 against the Computer Subroutine ---
- 720 FOR I=1 TO 9 'initialize array for storing moves
- 730 SQ(I)=0
- 740 NEXT I
- 750 GOSUB 4230 'erase box
- 760 REM X First move
- 770 GOSUB 1920 'ask for and make X move
- 780 REM O Second move Computer move
- 790 I=INT((RND*8)+1) 'pick random computer move
- 800 IF SQ(I) <> 0 THEN GOTO 790 'if square filled pick another
- 810 MOVE=I
- 820 GOSUB 3360 'load coordinates for move
- 830 GOSUB 3560 'draw move
- 840 REM X Third move
- 850 GOSUB 1920 'ask for and make X move
- 860 REM O Fourth move, Computer move
- 870 IF CH$="2" THEN GOTO 900 'easier game
- 880 MOVE=0:GOSUB 4280 'check for 2 in row, win and stop opponent
- 890 IF MOVE=0 THEN GOTO 900 ELSE GOTO 930 'if not 2 in row do random
- 900 I=INT((RND*8)+1) 'pick random computer move
- 910 IF SQ(I) <> 0 THEN GOTO 900 'if square filled pick another
- 920 MOVE=I
- 930 GOSUB 3360:GOSUB 3560 'make move
- 940 REM X Fifth move
- 950 GOSUB 1920 'ask for and make X move
- 960 WINSW=0:GOSUB 2270 'check for win
- 970 IF WINSW=4 THEN GOTO 1340 'X wins
- 980 REM O Sixth move, Computer move
- 990 IF CH$="2" THEN GOTO 1020 'easier game
- 1000 MOVE=0:GOSUB 4280 'check for 2 in row, win and stop opponent
- 1010 IF MOVE=0 THEN GOTO 1020 ELSE GOTO 1050 'if not 2 in row do random
- 1020 I=INT((RND*8)+1) 'pick random computer move
- 1030 IF SQ(I) <> 0 THEN GOTO 1020 'if square filled pick another
- 1040 MOVE=I
- 1050 GOSUB 3360:GOSUB 3560 'make move
- 1060 WINSW=0:GOSUB 2270 'check for win
- 1070 IF WINSW=1 THEN GOTO 1300 'Computer wins
- 1080 REM X Seventh move
- 1090 GOSUB 1920 'ask for and make X move
- 1100 WINSW=0:GOSUB 2270 'check for win
- 1110 IF WINSW=4 THEN GOTO 1340 'X wins
- 1120 REM O Eighth move, Computer move
- 1130 IF CH$="2" THEN GOTO 1160 'easier game
- 1140 MOVE=0:GOSUB 4280 'check for 2 in row, win and stop opponent
- 1150 IF MOVE=0 THEN GOTO 1160 ELSE GOTO 1190 'if not 2 in row do random
- 1160 I=INT((RND*8)+1) 'pick random computer move
- 1170 IF SQ(I) <> 0 THEN GOTO 1160 'if square filled pick another
- 1180 MOVE=I
- 1190 GOSUB 3360:GOSUB 3560 'make move
- 1200 WINSW=0:GOSUB 2270 'check for win
- 1210 IF WINSW=1 THEN GOTO 1300 'Computer wins
- 1220 REM X Nineth move
- 1230 GOSUB 1920 'ask for and make X move
- 1240 WINSW=0:GOSUB 2270 'check for win
- 1250 IF WINSW=4 THEN GOTO 1340 'X wins
- 1260 REM -- TIE --
- 1270 BEEP
- 1280 LOCATE 12,55,0:PRINT " TIE "
- 1290 GOTO 1370
- 1300 REM -- O WINS --
- 1310 BEEP
- 1320 LOCATE 12,55,0:PRINT " O - WINS"
- 1330 GOTO 1370
- 1340 REM -- X WINS --
- 1350 BEEP
- 1360 LOCATE 12,55,0:PRINT " X - WINS"
- 1370 COLOR 7,0 'Turn of blinking
- 1380 RETURN '----
- 1390 REM -- 2 player game Subroutine --
- 1400 FOR I=1 TO 9 'initialize array
- 1410 SQ(I)=0
- 1420 NEXT I
- 1430 MOVECNTR=0
- 1440 XOSW=4 'set to x move first
- 1450 GOSUB 4230 'erase box
- 1460 REM X First move
- 1470 GOSUB 1920 'ask for and make X move
- 1480 WINSW=0:GOSUB 2270 'check for win
- 1490 IF WINSW=4 THEN GOTO 1880 'X wins
- 1500 REM O Second move
- 1510 GOSUB 2090 'ask for and make O move
- 1520 WINSW=0:GOSUB 2270 'check for win
- 1530 IF WINSW=1 THEN GOTO 1850 'O wins
- 1540 REM X Third move
- 1550 GOSUB 1920 'ask for and make X move
- 1560 WINSW=0:GOSUB 2270 'check for win
- 1570 IF WINSW=4 THEN GOTO 1880 'X wins
- 1580 REM O Fourth move
- 1590 GOSUB 2090 'ask for and make O move
- 1600 WINSW=0:GOSUB 2270 'check for win
- 1610 IF WINSW=1 THEN GOTO 1850 'O wins
- 1620 REM X Fifth move
- 1630 GOSUB 1920 'ask for and make X move
- 1640 WINSW=0:GOSUB 2270 'check for win
- 1650 IF WINSW=4 THEN GOTO 1880 'X wins
- 1660 REM O Sixth move
- 1670 GOSUB 2090 'ask for and make O move
- 1680 WINSW=0:GOSUB 2270 'check for win
- 1690 IF WINSW=1 THEN GOTO 1850 'O wins
- 1700 REM X Seventh move
- 1710 GOSUB 1920 'ask for and make X move
- 1720 WINSW=0:GOSUB 2270 'check for win
- 1730 IF WINSW=4 THEN GOTO 1880 'X wins
- 1740 REM O Eighth move
- 1750 GOSUB 2090 'ask for and make O move
- 1760 WINSW=0:GOSUB 2270 'check for win
- 1770 IF WINSW=1 THEN GOTO 1850 'O wins
- 1780 REM X Nineth move
- 1790 GOSUB 1920 'ask for and make X move
- 1800 WINSW=0:GOSUB 2270 'check for win
- 1810 IF WINSW=4 THEN GOTO 1880 'X wins
- 1820 REM
- 1830 BEEP:LOCATE 12,55,0:PRINT " TIE ":BEEP
- 1840 GOTO 1900
- 1850 LOCATE 12,55,0:PRINT " O - WINS"
- 1860 BEEP
- 1870 GOTO 1900
- 1880 LOCATE 12,55,0:PRINT " X - WINS"
- 1890 BEEP
- 1900 COLOR 7,0 'return to default color, ie. end flashing
- 1910 RETURN '----
- 1920 REM --- Do X move subroutine ---
- 1930 LOCATE 7,46,0:PRINT ERASE1$
- 1940 LOCATE 8,46,0:PRINT ERASE1$
- 1950 LOCATE 9,46,0:PRINT ERASE1$
- 1960 LOCATE 7,47,0:PRINT "Enter move for X player"
- 1970 IN1$=INKEY$
- 1980 IF IN1$="" GOTO 1970
- 1990 IF ASC(IN1$) < 49 THEN GOTO 1970 'insure number 1-9
- 2000 IF ASC(IN1$) > 57 THEN GOTO 1970
- 2010 MOVE=VAL(IN1$) 'convert to number
- 2020 IN1$="" 'clear out
- 2030 SW=0 'set valid move switch
- 2040 GOSUB 3360 'load coordinates for move
- 2050 IF SW=1 THEN GOSUB 3470:GOTO 2080
- 2060 LOCATE 8,47,0:PRINT "That square filled, reenter"
- 2070 GOTO 1960
- 2080 RETURN '----
- 2090 REM --- Do O move Subroutine ---
- 2100 LOCATE 7,46,0:PRINT ERASE1$
- 2110 LOCATE 8,46,0:PRINT ERASE1$
- 2120 LOCATE 9,46,0:PRINT ERASE1$
- 2130 LOCATE 7,47,0:PRINT "Enter move for O player"
- 2140 IN1$=INKEY$
- 2150 IF IN1$="" GOTO 2140
- 2160 IF ASC(IN1$) < 49 THEN GOTO 2140 'insure number 1-9
- 2170 IF ASC(IN1$) > 57 THEN GOTO 2140
- 2180 MOVE=VAL(IN1$) 'convert to number
- 2190 IN1$="" 'clear out
- 2200 SW=0 'set valid move switch
- 2210 GOSUB 3360 'load coordinates for move
- 2220 IF SW=1 THEN GOSUB 3560:GOTO 2260
- 2230 LOCATE 8,47,0:PRINT "That square filled, reenter"
- 2240 LOCATE 7,46,0:PRINT ERASE1$ 'erase any err messages
- 2250 GOTO 2130
- 2260 RETURN '----
- 2270 REM --- Scan for a win ---
- 2280 IF SQ(1)=1 AND SQ(5)=1 AND SQ(9)=1 THEN GOTO 2290 ELSE GOTO 2350 'O wins
- 2290 WINSW=1
- 2300 COLOR 23
- 2310 R=2:C=14:GOSUB 3560 'draw flashing O in sq 1
- 2320 R=10:C=22:GOSUB 3560 'O in sq 5
- 2330 R=18:C=30:GOSUB 3560 'O in sq 9
- 2340 GOTO 3350
- 2350 IF SQ(7)=1 AND SQ(5)=1 AND SQ(3)=1 THEN GOTO 2360 ELSE GOTO 2420
- 2360 WINSW=1
- 2370 COLOR 23
- 2380 R=18:C=14:GOSUB 3560 'draw flashing O in sq 7
- 2390 R=10:C=22:GOSUB 3560 'sq 5
- 2400 R=2:C=30:GOSUB 3560 'sq 3
- 2410 GOTO 3350
- 2420 IF SQ(1)=1 AND SQ(2)=1 AND SQ(3)=1 THEN GOTO 2430 ELSE GOTO 2490
- 2430 WINSW=1
- 2440 COLOR 23
- 2450 R=2:C=14:GOSUB 3560 'draw flashing O in sq 1
- 2460 R=2:C=22:GOSUB 3560 'sq 2
- 2470 R=2:C=30:GOSUB 3560 'sq 3
- 2480 GOTO 3350
- 2490 IF SQ(4)=1 AND SQ(5)=1 AND SQ(6)=1 THEN GOTO 2500 ELSE GOTO 2560
- 2500 WINSW=1
- 2510 COLOR 23
- 2520 R=10:C=14:GOSUB 3560 'draw flashing O in sq 4
- 2530 R=10:C=22:GOSUB 3560 'sq 5
- 2540 R=10:C=30:GOSUB 3560 'sq 6
- 2550 GOTO 3350
- 2560 IF SQ(7)=1 AND SQ(8)=1 AND SQ(9)=1 THEN GOTO 2570 ELSE GOTO 2630
- 2570 WINSW=1
- 2580 COLOR 23
- 2590 R=18:C=14:GOSUB 3560 'draw flashing O in sq 7
- 2600 R=18:C=22:GOSUB 3560 'sq 8
- 2610 R=18:C=30:GOSUB 3560 'sq 9
- 2620 GOTO 3350
- 2630 IF SQ(1)=1 AND SQ(4)=1 AND SQ(7)=1 THEN GOTO 2640 ELSE GOTO 2700
- 2640 WINSW=1
- 2650 COLOR 23
- 2660 R=2:C=14:GOSUB 3560 'flashing O in sq 1
- 2670 R=10:C=14:GOSUB 3560 'sq 4
- 2680 R=18:C=14:GOSUB 3560 'sq 7
- 2690 GOTO 3350
- 2700 IF SQ(2)=1 AND SQ(5)=1 AND SQ(8)=1 THEN GOTO 2710 ELSE GOTO 2770
- 2710 WINSW=1
- 2720 COLOR 23
- 2730 R=2:C=22:GOSUB 3560 'flashing O in sq 2
- 2740 R=10:C=22:GOSUB 3560 'sq 5
- 2750 R=18:C=22:GOSUB 3560 'sq 8
- 2760 GOTO 3350
- 2770 IF SQ(3)=1 AND SQ(6)=1 AND SQ(9)=1 THEN GOTO 2780 ELSE GOTO 2840
- 2780 WINSW=1
- 2790 COLOR 23
- 2800 R=2:C=30:GOSUB 3560 'flashing O in sq 3
- 2810 R=10:C=30:GOSUB 3560 'sq 6
- 2820 R=18:C=30:GOSUB 3560 'sq 9
- 2830 GOTO 3350
- 2840 REM
- 2850 IF SQ(1)=4 AND SQ(5)=4 AND SQ(9)=4 THEN GOTO 2860 ELSE GOTO 2920 'X wins
- 2860 WINSW=4
- 2870 COLOR 23
- 2880 R=2:C=14:GOSUB 3470 'flashing X in sq 1
- 2890 R=10:C=22:GOSUB 3470 'sq 5
- 2900 R=18:C=30:GOSUB 3470 'sq 9
- 2910 GOTO 3350
- 2920 IF SQ(7)=4 AND SQ(5)=4 AND SQ(3)=4 THEN GOTO 2930 ELSE GOTO 2990
- 2930 WINSW=4
- 2940 COLOR 23
- 2950 R=18:C=14:GOSUB 3470 'flashing X in sq 7
- 2960 R=10:C=22:GOSUB 3470 'sq 5
- 2970 R=2:C=30:GOSUB 3470 'sq 3
- 2980 GOTO 3350
- 2990 IF SQ(1)=4 AND SQ(2)=4 AND SQ(3)=4 THEN GOTO 3000 ELSE GOTO 3060
- 3000 WINSW=4
- 3010 COLOR 23
- 3020 R=2:C=14:GOSUB 3470 'flashing X in sq 1
- 3030 R=2:C=22:GOSUB 3470 'sq 2
- 3040 R=2:C=30:GOSUB 3470 'sq 3
- 3050 GOTO 3350
- 3060 IF SQ(4)=4 AND SQ(5)=4 AND SQ(6)=4 THEN GOTO 3070 ELSE GOTO 3120
- 3070 WINSW=4:COLOR 23
- 3080 R=10:C=14:GOSUB 3470 'flashing X in sq 4
- 3090 R=10:C=22:GOSUB 3470 'sq 5
- 3100 R=10:C=30:GOSUB 3470 'sq 6
- 3110 GOTO 3350
- 3120 IF SQ(7)=4 AND SQ(8)=4 AND SQ(9)=4 THEN GOTO 3130 ELSE GOTO 3180
- 3130 WINSW=4:COLOR 23
- 3140 R=18:C=14:GOSUB 3470 'flashing X in sq 7
- 3150 R=18:C=22:GOSUB 3470 'sq 8
- 3160 R=18:C=30:GOSUB 3470 'sq 9
- 3170 GOTO 3350
- 3180 IF SQ(1)=4 AND SQ(4)=4 AND SQ(7)=4 THEN GOTO 3190 ELSE GOTO 3240
- 3190 WINSW=4:COLOR 23
- 3200 R=2:C=14:GOSUB 3470 'flashing X in sq 1
- 3210 R=10:C=14:GOSUB 3470 'sq 4
- 3220 R=18:C=14:GOSUB 3470 'sq 7
- 3230 GOTO 3350
- 3240 IF SQ(2)=4 AND SQ(5)=4 AND SQ(8)=4 THEN GOTO 3250 ELSE GOTO 3300
- 3250 WINSW=4:COLOR 23
- 3260 R=2:C=22:GOSUB 3470 'flashing X in sq 2
- 3270 R=10:C=22:GOSUB 3470 'sq 5
- 3280 R=18:C=22:GOSUB 3470 'sq 8
- 3290 GOTO 3350
- 3300 IF SQ(3)=4 AND SQ(6)=4 AND SQ(9)=4 THEN GOTO 3310 ELSE GOTO 3350
- 3310 WINSW=4:COLOR 23
- 3320 R=2:C=30:GOSUB 3470 'draw flashing X in sq 3
- 3330 R=10:C=30:GOSUB 3470 'sq 6
- 3340 R=18:C=30:GOSUB 3470 'sq 9
- 3350 RETURN '----
- 3360 REM --- Load coordinates for move ---
- 3370 IF MOVE=1 AND SQ(1)=0 THEN R=2:C=14:SW=1:GOTO 3460
- 3380 IF MOVE=2 AND SQ(2)=0 THEN R=2:C=22:SW=1:GOTO 3460
- 3390 IF MOVE=3 AND SQ(3)=0 THEN R=2:C=30:SW=1:GOTO 3460
- 3400 IF MOVE=4 AND SQ(4)=0 THEN R=10:C=14:SW=1:GOTO 3460
- 3410 IF MOVE=5 AND SQ(5)=0 THEN R=10:C=22:SW=1:GOTO 3460
- 3420 IF MOVE=6 AND SQ(6)=0 THEN R=10:C=30:SW=1:GOTO 3460
- 3430 IF MOVE=7 AND SQ(7)=0 THEN R=18:C=14:SW=1:GOTO 3460
- 3440 IF MOVE=8 AND SQ(8)=0 THEN R=18:C=22:SW=1:GOTO 3460
- 3450 IF MOVE=9 AND SQ(9)=0 THEN R=18:C=30:SW=1:GOTO 3460
- 3460 RETURN '----
- 3470 REM --- Draw X Subroutine ---
- 3480 FOR I=0 TO 4
- 3490 LOCATE R+I,C+I,0:PRINT CHR$(D)
- 3500 LOCATE R+I,C+4-I,0:PRINT CHR$(D)
- 3510 NEXT I
- 3520 SQ(MOVE)=4 '4 represents X, 1 represents O and 0 means empty
- 3530 XOSW=1 'set next move to be Os
- 3540 MOVECNTR=MOVECNTR+1
- 3550 RETURN '----
- 3560 REM --- Draw O Subroutine ---
- 3570 FOR I=0 TO 4
- 3580 LOCATE R,C+I,0:PRINT CHR$(D)
- 3590 LOCATE R+I,C+4,0:PRINT CHR$(D)
- 3600 LOCATE R+4,C+4-I,0:PRINT CHR$(D)
- 3610 LOCATE R+4-I,C,0:PRINT CHR$(D)
- 3620 NEXT I
- 3630 SQ(MOVE)=1 '4 represents X, 1 represents O and 0 means empty
- 3640 XOSW=1 'set next move to be Os
- 3650 MOVECNTR=MOVECNTR+1
- 3660 RETURN '----
- 3670 REM -- Subroutine to draw lines and initialize ---
- 3680 D=219 'density of Xs and Os
- 3690 R=10
- 3700 C=22
- 3710 FILLED=0
- 3720 ERASE1$=" " 'used to erase box
- 3730 FOR I=0 TO 9
- 3740 SQ(I)=0
- 3750 NEXT I
- 3760 FOR I=13 TO 35
- 3770 LOCATE 8,I,0:PRINT CHR$(219)
- 3780 LOCATE 16,I,0:PRINT CHR$(219)
- 3790 NEXT I
- 3800 FOR I=1 TO 23
- 3810 LOCATE I,20,0:PRINT CHR$(219)
- 3820 LOCATE I,28,0:PRINT CHR$(219)
- 3830 NEXT I
- 3840 LOCATE 7,16,0:PRINT "1"
- 3850 LOCATE 7,24,0:PRINT "2"
- 3860 LOCATE 7,32,0:PRINT "3"
- 3870 LOCATE 15,16,0:PRINT "4"
- 3880 LOCATE 15,24,0:PRINT "5"
- 3890 LOCATE 15,32,0:PRINT "6"
- 3900 LOCATE 23,16,0:PRINT "7"
- 3910 LOCATE 23,24,0:PRINT "8"
- 3920 LOCATE 23,32,0:PRINT "9"
- 3930 FOR I=2 TO 22
- 3940 LOCATE I,45,0:PRINT CHR$(186)
- 3950 LOCATE I,75,0:PRINT CHR$(186)
- 3960 NEXT I
- 3970 LOCATE 1,45,0:PRINT CHR$(201)
- 3980 LOCATE 1,75,0:PRINT CHR$(187)
- 3990 LOCATE 23,45,0:PRINT CHR$(200)
- 4000 LOCATE 23,75,0:PRINT CHR$(188)
- 4010 FOR I=46 TO 74
- 4020 LOCATE 1,I,0:PRINT CHR$(205)
- 4030 LOCATE 23,I,0:PRINT CHR$(205)
- 4040 NEXT I
- 4050 LOCATE 3,55,0:PRINT "TIC TAC TOE"
- 4060 RETURN '----
- 4070 REM --- Print instructions subroutine ---
- 4080 GOSUB 4230 'erase box
- 4090 LOCATE 5,47,0:PRINT "WIN - by placing three X or"
- 4100 LOCATE 6,47,0:PRINT " O in a straight line"
- 4110 LOCATE 7,47,0:PRINT " (vertical, horizontal"
- 4120 LOCATE 8,47,0:PRINT " or diagonal)"
- 4130 LOCATE 10,47,0:PRINT "Move by entering the number"
- 4140 LOCATE 11,47,0:PRINT " of the square you want to"
- 4150 LOCATE 12,47,0:PRINT " move to."
- 4160 LOCATE 14,47,0:PRINT "You cannot move to a square"
- 4170 LOCATE 15,47,0:PRINT " that is filled."
- 4180 LOCATE 18,47,0:PRINT "Press any key to continue."
- 4190 DEL$=INKEY$:IF DEL$="" THEN GOTO 4190 'sense input - delay only
- 4200 GOSUB 4230 'erase box
- 4210 RETURN '----
- 4220 REM
- 4230 REM --- Erase box Subroutine ---
- 4240 FOR I=4 TO 22
- 4250 LOCATE I,46,0:PRINT ERASE1$
- 4260 NEXT I
- 4270 RETURN '----
- 4280 REM --- Check for Win move for O ---
- 4290 IF SQ(1)+SQ(2)+SQ(3)=2 GOTO 4300 ELSE GOTO 4340
- 4300 IF SQ(1)=0 THEN MOVE=1
- 4310 IF SQ(2)=0 THEN MOVE=2
- 4320 IF SQ(3)=0 THEN MOVE=3
- 4330 GOTO 5100 ' out of subroutine
- 4340 IF SQ(4)+SQ(5)+SQ(6)=2 GOTO 4350 ELSE GOTO 4390
- 4350 IF SQ(4)=0 THEN MOVE=4
- 4360 IF SQ(5)=0 THEN MOVE=5
- 4370 IF SQ(6)=0 THEN MOVE=6
- 4380 GOTO 5100 ' out
- 4390 IF SQ(7)+SQ(8)+SQ(9)=2 GOTO 4400 ELSE GOTO 4440
- 4400 IF SQ(7)=0 THEN MOVE=7
- 4410 IF SQ(8)=0 THEN MOVE=8
- 4420 IF SQ(9)=0 THEN MOVE=9
- 4430 GOTO 5100 ' out
- 4440 IF SQ(1)+SQ(4)+SQ(7)=2 GOTO 4450 ELSE GOTO 4490
- 4450 IF SQ(1)=0 THEN MOVE=1
- 4460 IF SQ(4)=0 THEN MOVE=4
- 4470 IF SQ(7)=0 THEN MOVE=7
- 4480 GOTO 5100 ' out
- 4490 IF SQ(2)+SQ(5)+SQ(8)=2 GOTO 4500 ELSE GOTO 4540
- 4500 IF SQ(2)=0 THEN MOVE=2
- 4510 IF SQ(5)=0 THEN MOVE=5
- 4520 IF SQ(8)=0 THEN MOVE=8
- 4530 GOTO 5100 ' out
- 4540 IF SQ(3)+SQ(6)+SQ(9)=2 GOTO 4550 ELSE GOTO 4590
- 4550 IF SQ(3)=0 THEN MOVE=3
- 4560 IF SQ(6)=0 THEN MOVE=6
- 4570 IF SQ(9)=0 THEN MOVE=9
- 4580 GOTO 5100 ' out
- 4590 IF SQ(1)+SQ(5)+SQ(9)=2 GOTO 4600 ELSE GOTO 4640
- 4600 IF SQ(1)=0 THEN MOVE=1
- 4610 IF SQ(5)=0 THEN MOVE=5
- 4620 IF SQ(9)=0 THEN MOVE=9
- 4630 GOTO 5100 ' out
- 4640 IF SQ(3)+SQ(5)+SQ(7)=2 GOTO 4650 ELSE GOTO 4710
- 4650 IF SQ(3)=0 THEN MOVE=3
- 4660 IF SQ(5)=0 THEN MOVE=5
- 4670 IF SQ(7)=0 THEN MOVE=7
- 4680 GOTO 5100 ' out of subroutine
- 4690 REM
- 4700 REM -- Following checks to stop 2 Xs in a row --
- 4710 IF SQ(1)+SQ(2)+SQ(3)=8 GOTO 4720 ELSE GOTO 4760
- 4720 IF SQ(1)=0 THEN MOVE=1
- 4730 IF SQ(2)=0 THEN MOVE=2
- 4740 IF SQ(3)=0 THEN MOVE=3
- 4750 GOTO 5100 ' out of subroutine
- 4760 IF SQ(4)+SQ(5)+SQ(6)=8 GOTO 4770 ELSE GOTO 4810
- 4770 IF SQ(4)=0 THEN MOVE=4
- 4780 IF SQ(5)=0 THEN MOVE=5
- 4790 IF SQ(6)=0 THEN MOVE=6
- 4800 GOTO 5100 ' out
- 4810 IF SQ(7)+SQ(8)+SQ(9)=8 GOTO 4820 ELSE GOTO 4860
- 4820 IF SQ(7)=0 THEN MOVE=7
- 4830 IF SQ(8)=0 THEN MOVE=8
- 4840 IF SQ(9)=0 THEN MOVE=9
- 4850 GOTO 5100 ' out
- 4860 IF SQ(1)+SQ(4)+SQ(7)=8 GOTO 4870 ELSE GOTO 4910
- 4870 IF SQ(1)=0 THEN MOVE=1
- 4880 IF SQ(4)=0 THEN MOVE=4
- 4890 IF SQ(7)=0 THEN MOVE=7
- 4900 GOTO 5100 ' out
- 4910 IF SQ(2)+SQ(5)+SQ(8)=8 GOTO 4920 ELSE GOTO 4960
- 4920 IF SQ(2)=0 THEN MOVE=2
- 4930 IF SQ(5)=0 THEN MOVE=5
- 4940 IF SQ(8)=0 THEN MOVE=8
- 4950 GOTO 5100 ' out
- 4960 IF SQ(3)+SQ(6)+SQ(9)=8 GOTO 4970 ELSE GOTO 5010
- 4970 IF SQ(3)=0 THEN MOVE=3
- 4980 IF SQ(6)=0 THEN MOVE=6
- 4990 IF SQ(9)=0 THEN MOVE=9
- 5000 GOTO 5100 ' out
- 5010 IF SQ(1)+SQ(5)+SQ(9)=8 GOTO 5020 ELSE GOTO 5060
- 5020 IF SQ(1)=0 THEN MOVE=1
- 5030 IF SQ(5)=0 THEN MOVE=5
- 5040 IF SQ(9)=0 THEN MOVE=9
- 5050 GOTO 5100 ' out
- 5060 IF SQ(3)+SQ(5)+SQ(7)=8 GOTO 5070 ELSE GOTO 5100
- 5070 IF SQ(3)=0 THEN MOVE=3
- 5080 IF SQ(5)=0 THEN MOVE=5
- 5090 IF SQ(7)=0 THEN MOVE=7
- 5100 RETURN '----
- 5110 REM --- Most difficult game against the Computer 4 ---
- 5120 FOR I=1 TO 9 'initialize array that indicates empty squares
- 5130 SQ(I)=0
- 5140 NEXT I
- 5150 GOSUB 4230 'erase box
- 5160 REM X First move
- 5170 GOSUB 1920 'ask for and make X move
- 5180 REM O Second move Computer move
- 5190 IF SQ(5)=0 THEN MOVE=5:GOTO 5250 ELSE GOTO 5200
- 5200 I=INT((RND*3)+1) 'pick one of 4 corners randomly
- 5210 IF I=1 THEN MOVE=1
- 5220 IF I=2 THEN MOVE=3
- 5230 IF I=3 THEN MOVE=7
- 5240 IF I=4 THEN MOVE=9
- 5250 GOSUB 3360 'load coordinates for move
- 5260 GOSUB 3560 'draw move
- 5270 REM X Third move
- 5280 GOSUB 1920 'ask for and make X move
- 5290 REM O Fourth move, Computer move
- 5300 MOVE=0:GOSUB 4280 'check for 2 in row, win and stop opponent
- 5310 IF MOVE=0 THEN GOTO 5320 ELSE GOTO 5440 'if not 2 in row continue
- 5320 IF SQ(1)=4 AND SQ(9)=4 THEN GOTO 5350
- 5330 IF SQ(3)=4 AND SQ(7)=4 THEN GOTO 5350
- 5340 GOTO 5410 'pick a random move
- 5350 I=INT((RND*3)+1) 'pick one of 4 sides randomly
- 5360 IF I=1 THEN MOVE=2
- 5370 IF I=2 THEN MOVE=4
- 5380 IF I=3 THEN MOVE=6
- 5390 IF I=4 THEN MOVE=8
- 5400 GOTO 5440 'make move
- 5410 I=INT((RND*8)+1) 'pick random computer move
- 5420 IF SQ(I) <> 0 THEN GOTO 5350 'if square filled pick another
- 5430 MOVE=I
- 5440 GOSUB 3360:GOSUB 3560 'make move
- 5450 REM X Fifth move
- 5460 GOSUB 1920 'ask for and make X move
- 5470 WINSW=0:GOSUB 2270 'check for win
- 5480 IF WINSW=4 THEN GOTO 5830 'X wins
- 5490 REM O Sixth move, Computer move
- 5500 MOVE=0:GOSUB 4280 'check for 2 in row, win and stop opponent
- 5510 IF MOVE=0 THEN GOTO 5520 ELSE GOTO 5550 'if not 2 in row do random
- 5520 I=INT((RND*8)+1) 'pick random computer move
- 5530 IF SQ(I) <> 0 THEN GOTO 5520 'if square filled pick another
- 5540 MOVE=I
- 5550 GOSUB 3360:GOSUB 3560 'make move
- 5560 WINSW=0:GOSUB 2270 'check for win
- 5570 IF WINSW=1 THEN GOTO 5790 'Computer wins
- 5580 REM X Seventh move
- 5590 GOSUB 1920 'ask for and make X move
- 5600 WINSW=0:GOSUB 2270 'check for win
- 5610 IF WINSW=4 THEN GOTO 5830 'X wins
- 5620 REM O Eighth move, Computer move
- 5630 MOVE=0:GOSUB 4280 'check for 2 in row, win and stop opponent
- 5640 IF MOVE=0 THEN GOTO 5650 ELSE GOTO 5680 'if not 2 in row do random
- 5650 I=INT((RND*8)+1) 'pick random computer move
- 5660 IF SQ(I) <> 0 THEN GOTO 5650 'if square filled pick another
- 5670 MOVE=I
- 5680 GOSUB 3360:GOSUB 3560 'make move
- 5690 WINSW=0:GOSUB 2270 'check for win
- 5700 IF WINSW=1 THEN GOTO 5790 'Computer wins
- 5710 REM X Nineth move
- 5720 GOSUB 1920 'ask for and make X move
- 5730 WINSW=0:GOSUB 2270 'check for win
- 5740 IF WINSW=4 THEN GOTO 5830 'X wins
- 5750 REM -- TIE --
- 5760 BEEP
- 5770 LOCATE 12,55,0:PRINT " TIE "
- 5780 GOTO 5860
- 5790 REM -- O WINS --
- 5800 BEEP
- 5810 LOCATE 12,55,0:PRINT " O - WINS"
- 5820 GOTO 5860
- 5830 REM -- X WINS --
- 5840 BEEP
- 5850 LOCATE 12,55,0:PRINT " X - WINS"
- 5860 COLOR 7,0 'Turn off blinking
- 5870 RETURN '---
- 5880 REM ---- Randomize Subroutine ---
- 5890 REM This subroutine substitutes for the randomize command. It picks off
- 5900 REM 4 digits from the time field and uses this to seed the random nbr.
- 5910 A$=TIME$
- 5920 B$=MID$(A$,4,2)+RIGHT$(A$,2)
- 5930 TIME=VAL(B$)
- 5940 RANDOMIZE TIME 'seed random nbr generator
- 5950 RETURN '---
-